package com.freight.order.controller;


import com.freight.core.common.utils.ResultUtil;
import com.freight.core.common.vo.Result;
import com.freight.order.dto.QuotationDto;
import com.freight.order.entity.QuotationDetails;
import com.freight.order.service.DriverQuotationRecordService;
import com.freight.order.vo.QuotationRecordVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@Api(description = "抢单接口")
@RequestMapping("/freight/driverQuotationRecord")
@Transactional
public class DriverQuotationRecordController {

    @Autowired
    private DriverQuotationRecordService driverQuotationRecordService;

    @RequestMapping(value = "/addQuotationRecord", method = RequestMethod.POST)
    @ApiOperation(value = "抢单 填写装车时间、修改装车时间")
    public Result<String> addQuotationRecord(QuotationDto quotationDto) {
        driverQuotationRecordService.addQuotationRecord(quotationDto);
        return ResultUtil.success("操作成功");
    }

    @RequestMapping(value = "/cancelQuotationRecord", method = RequestMethod.POST)
    @ApiOperation(value = "取消抢单")
    public Result<String> cancelQuotationRecord(Long quotationRecordId) {
        driverQuotationRecordService.cancelQuotationRecord(quotationRecordId);
        return ResultUtil.success("操作成功");
    }

    @RequestMapping(value = "/driverQuotationRecord", method = RequestMethod.GET)
    @ApiOperation(value = "根据货源ID获取报价记录")
    public Result<List<QuotationRecordVo>> driverQuotationRecord(Long orderGoodsId) {
        List<QuotationRecordVo> page = driverQuotationRecordService.driverQuotationRecord(orderGoodsId);
        return new ResultUtil<List<QuotationRecordVo>>().setData(page);
    }

    @RequestMapping(value = "/driverQuotationState", method = RequestMethod.GET)
    @ApiOperation(value = "根据货源ID获取报价状态")
    public Result<QuotationRecordVo> driverQuotationState(Long orderGoodsId) {
        QuotationRecordVo page = driverQuotationRecordService.driverQuotationState(orderGoodsId);
        return new ResultUtil<QuotationRecordVo>().setData(page);
    }

    @RequestMapping(value = "/quotationModifyList", method = RequestMethod.GET)
    @ApiOperation(value = "获取报价修改记录列表")
    public Result<List<QuotationDetails>> quotationModifyList(Long quotationRecordId) {
        List<QuotationDetails> page = driverQuotationRecordService.quotationModifyList(quotationRecordId);
        return new ResultUtil<List<QuotationDetails>>().setData(page);
    }

}
